package edu.hrbu.service.impl;

import edu.hrbu.mapper.RoleMapper;
import edu.hrbu.pojo.Role;
import edu.hrbu.service.RoleService;
import edu.hrbu.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author 徐登宇
 * @date 2022-10-27 19:13
 */
public class RoleServiceImpl implements RoleService {
    @Override
    public Role getRoleByRoleId(int roleId) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        RoleMapper mapper = sqlSession.getMapper(RoleMapper.class);
        Role role = mapper.getRoleByRoleId(roleId);
        sqlSession.close();
        return role;
    }

    @Override
    public List<Role> getRoleList() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        RoleMapper mapper = sqlSession.getMapper(RoleMapper.class);
        List<Role> roleList = mapper.getRoleList();
        sqlSession.close();
        return roleList;
    }

    @Override
    public List<Role> getRoleAndCount() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        RoleMapper mapper = sqlSession.getMapper(RoleMapper.class);
        List<Role> roleList = mapper.getRoleAndCount();
        sqlSession.close();
        return roleList;
    }
}
